package com.example.sqlitedemo.greendao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.example.sqlitedemo.dao.entity.FaceFeature;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "t_facefeature".
*/
public class FaceFeatureDao extends AbstractDao<FaceFeature, String> {

    public static final String TABLENAME = "t_facefeature";

    /**
     * Properties of entity FaceFeature.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Uuid = new Property(0, String.class, "uuid", true, "UUID");
        public final static Property PhotoMd5 = new Property(1, String.class, "photoMd5", false, "photo_md5");
        public final static Property FaceTonken = new Property(2, String.class, "faceTonken", false, "face_tonken");
        public final static Property FaceMd5 = new Property(3, String.class, "faceMd5", false, "face_md5");
    }

    private Query<FaceFeature> shootPhoto_FaceListQuery;

    public FaceFeatureDao(DaoConfig config) {
        super(config);
    }
    
    public FaceFeatureDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"t_facefeature\" (" + //
                "\"UUID\" TEXT PRIMARY KEY NOT NULL ," + // 0: uuid
                "\"photo_md5\" TEXT," + // 1: photoMd5
                "\"face_tonken\" TEXT," + // 2: faceTonken
                "\"face_md5\" TEXT);"); // 3: faceMd5
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"t_facefeature\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, FaceFeature entity) {
        stmt.clearBindings();
 
        String uuid = entity.getUuid();
        if (uuid != null) {
            stmt.bindString(1, uuid);
        }
 
        String photoMd5 = entity.getPhotoMd5();
        if (photoMd5 != null) {
            stmt.bindString(2, photoMd5);
        }
 
        String faceTonken = entity.getFaceTonken();
        if (faceTonken != null) {
            stmt.bindString(3, faceTonken);
        }
 
        String faceMd5 = entity.getFaceMd5();
        if (faceMd5 != null) {
            stmt.bindString(4, faceMd5);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, FaceFeature entity) {
        stmt.clearBindings();
 
        String uuid = entity.getUuid();
        if (uuid != null) {
            stmt.bindString(1, uuid);
        }
 
        String photoMd5 = entity.getPhotoMd5();
        if (photoMd5 != null) {
            stmt.bindString(2, photoMd5);
        }
 
        String faceTonken = entity.getFaceTonken();
        if (faceTonken != null) {
            stmt.bindString(3, faceTonken);
        }
 
        String faceMd5 = entity.getFaceMd5();
        if (faceMd5 != null) {
            stmt.bindString(4, faceMd5);
        }
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
    }    

    @Override
    public FaceFeature readEntity(Cursor cursor, int offset) {
        FaceFeature entity = new FaceFeature( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // uuid
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // photoMd5
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // faceTonken
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // faceMd5
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, FaceFeature entity, int offset) {
        entity.setUuid(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setPhotoMd5(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setFaceTonken(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setFaceMd5(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
     }
    
    @Override
    protected final String updateKeyAfterInsert(FaceFeature entity, long rowId) {
        return entity.getUuid();
    }
    
    @Override
    public String getKey(FaceFeature entity) {
        if(entity != null) {
            return entity.getUuid();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(FaceFeature entity) {
        return entity.getUuid() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "faceList" to-many relationship of ShootPhoto. */
    public List<FaceFeature> _queryShootPhoto_FaceList(String faceMd5) {
        synchronized (this) {
            if (shootPhoto_FaceListQuery == null) {
                QueryBuilder<FaceFeature> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.FaceMd5.eq(null));
                shootPhoto_FaceListQuery = queryBuilder.build();
            }
        }
        Query<FaceFeature> query = shootPhoto_FaceListQuery.forCurrentThread();
        query.setParameter(0, faceMd5);
        return query.list();
    }

}
